#coding=utf-8
from uliweb.orm import *
from uliweb.utils.common import get_var
from uliweb.i18n import ugettext_lazy as _

def get_modified_user():
    from uliweb import request
    
    return request.user.id

class Poll(Model):
    __verbose_name__ = u'投票'
    
    name = Field(str, max_length=255, verbose_name='投票名称')
    slug = Field(str, max_length=40, verbose_name='投票标识', unique=True, index=True)
    desc = Field(TEXT, verbose_name='投票说明')
    begin_date = Field(datetime.date, verbose_name='开始时间')
    end_date = Field(datetime.date, verbose_name='结束时间')
    link = Field(str, max_length=255, verbose_name='链接')
    managers = ManyToMany('user', verbose_name='管理员')
    
    def __unicode__(self):
        return self.name

def poll_manager(user, poll_id):
    """
    判断用户是否是某投票的管理员
    """
    from uliweb.orm import get_model
    
    Poll = get_model('poll')
    poll = Poll.get(poll_id)
    return bool(user and poll and poll.managers.has(user))
